package com.neulogistics.core.substation.api;

import com.blackto.lib.eventbus.abstraction.IEventBus;
import com.blackto.lib.eventbus.abstraction.IIntegrationEventHandler;
import com.neulogistics.core.substation.api.application.integrationevent.subscribe.PickUpOutboundIntegrationEvent;
import com.neulogistics.core.substation.api.application.integrationevent.subscribe.SubstationReturnInboundIntegrationEvent;
import com.neulogistics.core.substation.api.application.integrationevent.subscribe.TransferInboundIntegrationEvent;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class Initializer implements ApplicationRunner {
    private IEventBus eventBus;

    @Resource
    IIntegrationEventHandler<PickUpOutboundIntegrationEvent> pickUpOutboundIntegrationEventHandler;

    @Resource
    IIntegrationEventHandler<TransferInboundIntegrationEvent> transferInboundIntegrationEventHandler;

    @Resource
    IIntegrationEventHandler<SubstationReturnInboundIntegrationEvent> substationReturnInboundIntegrationEventHandler;

    public Initializer(IEventBus eventBus) {
        this.eventBus = eventBus;
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
        // 在此订阅本项目需要接受的集成事件，并指定handler
        eventBus.subscribe(PickUpOutboundIntegrationEvent.class, pickUpOutboundIntegrationEventHandler.getClass());
        eventBus.subscribe(TransferInboundIntegrationEvent.class, transferInboundIntegrationEventHandler.getClass());
        eventBus.subscribe(SubstationReturnInboundIntegrationEvent.class, substationReturnInboundIntegrationEventHandler.getClass());
    }
}
